package com.alignet.gn.util;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import org.apache.commons.lang.math.NumberUtils;



@FacesValidator("amount")
public class AmountValidator implements Validator {
  public static final String VALIDATOR_ID = "amount";
  
  public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException {
    final String valor = (String) value;

	try {
	    if (valor == null) {
			return;
	    }else{
			if(NumberUtils.isNumber(valor)){
				return;		
			}	    	
	    }		

	} catch (NumberFormatException e) {
		throw new ValidatorException(new FacesMessage("Monto Invalido"));
	}    
    
    throw new ValidatorException(new FacesMessage("Monto Invalido"));
  }
}